class TaskPro {
    taskLink = {
        exec: () => {},
        next: null,
    }
    constructor() {
        this.lastTask = this.taskLink;
    }
    addTask(taskExector) {
        const newTask = {
            exec: taskExector,
            next: null
        };
        this.lastTask.next = newTask;
        this.lastTask = newTask;
    }
    taskWrapper(task) {
        if (!task) {
            return null;
        }
        return () => {
            const next = this.taskWrapper(task.next) || (() => {});
            let exn = false;
            const res = task.exec(() => {
                exn = true;
                next();
            });
            if(!exn) {
                next();
            }
        }
    }
    run() {
        let t = this.taskWrapper(this.taskLink.next);
        t();
    }
}
const t = new TaskPro();
t.addTask((next) => {
    console.log("task1");
    setTimeout(() => {
        next();
    }, 1000);
})
t.addTask(() => {
    console.log("task2");
})
t.addTask(() => {
    console.log("task3");
})
t.run();